const mysql = require('mysql2');
require('dotenv').config(); 
const connection = mysql.createConnection({
  host: process.env.DB_HOST,
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_DATABASE
});

connection.connect(err => {
  if (err) {
    console.error('Error connecting to the database:', err);
    throw err;
  }
  console.log('Connected to MySQL Database');
});

connection.on('error', err => {
  console.error('Database error:', err);
});

module.exports = connection;